<?php

class company_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->tableName = "company";
    }

    function insert($company_name, $company_address, $cityid, $provinceid, $description, $createddate, $createdby, $updateddate, $updatedby) {
        $dt = array("company_name" => $company_name,
            "company_address" => $company_address,
            "city_id" => $cityid,
            "province_id" => $provinceid,
            "company_description" => $descr,
            "createddate" => $createddate,
            "createdby" => $createdby,
            "updateddate" => $updateddate,
            "updatedby" => $updatedby);
        $this->db->insert($this->tableName, $dt);
        return $this->db->insert_id();
    }

    function update($company_id, $dt, $where = "") {
        $this->db->where("company_id", $company_id);
        if ($where != "")
            $this->db->where($where);
        $this->db->update($this->tableName, $dt);
    }

    function delete($company_id, $where = "") {
        $this->db->where("company_id", $company_id);
        if ($where != "")
            $this->db->where($where);
        $this->db->delete($this->tableName);
    }

    function getById($company_id, $where = "") {
        $this->db->where("company_id", $company_id);
        if ($where != "")
            $this->db->where($where);
        return $this->db->get($this->tableName)->row();
    }

    function getAll($startpage = "0", $perpage = "10", $where = "", $like="", $orderby = "") {
        if ($where != "")
            $this->db->where($where);
        if ($like != "")
            $this->db->like($like);
        $this->db->limit($perpage, $startpage);
        if ($orderby != "")
            $this->db->order_by($orderby);
        return $this->db->get($this->tableName)->result();
    }

    function getAllCount($where = "", $like = "") {
        $this->db->select("COUNT(*) JUMLAH");
        $this->db->from($this->tableName);
        if ($like != "")
            $this->db->like($like);
        if ($where != "")
            $this->db->where($where);
        return $this->db->get()->row()->JUMLAH;
    }

}

?>